/*
 * Copyright (c) Scrap Material Junior Brother, Xin. 2023-2023. All rights reserved.
 */

package collection;

import java.util.ArrayDeque;

/**
 * ArrayDeque实现栈和队列(性能优于LinkedList)
 *
 * @author xin
 * @since 2023-05-02
 */
public class ArrayDequeApi {
    public static void main(String[] args) {
        ArrayDeque<Character> deque = new ArrayDeque<>();
        deque.add('B');
        System.out.println(deque);
        deque.add('A');
        System.out.println(deque);
        deque.addLast('D');
        System.out.println(deque);
        deque.addFirst('C');
        System.out.println(deque);
        // 查看末位，不移除
        System.out.println(deque.getLast());
        // 查看首位，不移除
        System.out.println(deque.getFirst());
        // 移除首位
        deque.removeFirst();
        System.out.println(deque);
        // 移除末位
        deque.removeLast();
        System.out.println(deque);
        System.out.println(deque.isEmpty());
    }
}
